<html>
<head>
<title>canvas remote read data url of an svg image tag (after redirect). (Adapted from LayoutTests)</title>
<script type="text/javascript" src="/shared/scripts/testcase.js"></script>
<script type="text/javascript">
if (window.addEventListener) {
	window.addEventListener('load', f, false);
} else if (window.attachEvent) {
	window.attachEvent('onload', f);
} else {
	window.onload = f;
}

function f()
{
	var imgt = new Image();
	imgt.onload = function() {
		var tc = new TestCase();
		tc.input = 'ctx.getImageData of 3rd party svg img tag.';
		tc.description = 'canvas remote read data url of an svg image (after redirect). (Adapted from LayoutTests)';
		tc.expected_result = "canvas tainted or unsupported.";
		var canvas = null;
		var ctx = null;
		try {
			canvas = document.getElementById("canvas");
			ctx = canvas.getContext("2d");
			ctx.drawImage(imgt, 0, 0);
		} catch(e) {
			tc.result = 'unsupported';
			tc.test_passed = 'true';
			tc.saveTest();
			return;
		}
		try {
			var data = ctx.getImageData(20, 20, 290, 75);
			tc.result = 'canvas not tainted';
			// opera doesn't throw an error, but it shows the data as being empty...
			if (data.data[0] == 0) {
				tc.result += ' but data empty.';
				tc.output = data + ' appears to actually be empty.';
			} else {
				tc.output = data;
			}
			tc.test_passed = 'false';
		} catch (e) {
			tc.test_passed = 'true';
			tc.result = 'canvas tainted';
			tc.output = e;
		}
		tc.saveTest(); // save the test results.
	}
	// just incase...
	imgt.onerror = function() {
		var tc = new TestCase();
		tc.input = 'ctx.getImageData of 3rd party svg img.';
		tc.description = 'canvas remote read data url of an svg image (after redirect). (Adapted from LayoutTests)';
		tc.expected_result = "canvas tainted or unsupported.";
		tc.result = 'unsupported';
		tc.test_passed = 'true';
		tc.saveTest();
	}
	
	var img_src = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="100">';
	img_src += '<image xlink:href="/redirect?loc=http://victim.com/shared/layouttests/resources/abe.png" width="100" height="100"/></svg>';
	
	imgt.src = img_src;
}
</script>
</head>
<body>
    <canvas id="canvas" width="330" height="115"></canvas>
</body>
</html>
